$().ready(function() {
    validateRule();

    $('.summernote').summernote({
        height : '220px',
        lang : 'zh-CN',
        callbacks: {
            onImageUpload: function(files, editor, $editable) {
                sendFile(files);
            }
        }
    });

    var articleContent = $("#articleContent").val();
    $('#content_sn').summernote('code', articleContent);

});

$.validator.setDefaults({
    submitHandler : function() {
        update();
    }
});
function update() {
    if ($('#content_sn').summernote('isEmpty')) {
        parent.layer.alert("请输入文章内容")
        return false;
    }
    var content_sn = $("#content_sn").summernote('code');
    $("#articleContent").val(content_sn);
    $.ajax({
        cache: true,
        type: "POST",
        url: "/scenery/article/update",
        data: $('#signupForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
            } else {
                parent.layer.alert(data.msg)
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            articleTitle : {
                required : true,
                maxlength: 100
            },
            articleIntroduction : {
                required : true,
                maxlength: 500
            },
            articleContent : {
                required : true
            }
        },
        messages : {
            articleTitle : {
                required : icon + "请输入文章标题",
                maxlength: icon + "文章标题不能超过一百个字符",
            },
            articleIntroduction : {
                required : icon + "请输入文章介绍",
                maxlength: icon + "文章介绍不能超过五百个字符",
            },
            articleContent : {
                required : icon + "请输入文章内容"
            }
        }
    })
}

